<template>
  <view class="operate-page">
    <!-- 顶部导航栏 -->
    <!-- 操作说明列表 -->
    <view class="operate-list">
      <view v-for="(item, index) in dataList" :key="index" class="operate-item" @click="handleDetail(item)">
        <!-- 左侧图片 -->
        <image :src="config.beaeUrl + item.cover" mode="aspectFill" class="item-image"></image>
        <!-- 右侧内容 -->
        <view class="item-content">
          <view class="item-text">{{ item.name||"-" }}</view>
          <view class="item-time">{{ item.createTime||'-' }}</view>
        </view>
      </view>
    </view>
    <uv-load-more :status="status" line height="60" v-if="dataList.length!=0" />
  </view>
</template>

<script setup>
  import { ref } from 'vue'
  import { getOperationList } from '@/api/index.js'
  import { onLoad, onPullDownRefresh, onReachBottom, onShow } from '@dcloudio/uni-app'
  import config from '@/config/public'
  const status = ref("loadmore"); // 加载状态
  // 操作说明列表数据
  const dataList = ref([])
  const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
  })
  const total = ref(0)

  onShow(() => {
    getList()
  })
  // 下拉刷新
  onPullDownRefresh(() => {
    queryParams.value.pageNum = 1;
    getList();
  });

  const getList = () => {
    status.value = "loading";
    getOperationList(queryParams.value).then((res) => {
      if (res.code == 200) {
        dataList.value = queryParams.value.pageNum == 1 ? res.rows : dataList.value.concat(res.rows);
        total.value = res.total;
      }
    })
      .finally(() => {
        status.value = total.value == dataList.value.length ? "nomore" : "loadmore";
        uni.stopPullDownRefresh();
      });
  }
  // 上拉加载
  onReachBottom(() => {
    if (dataList.value.length < total.value) {
      queryParams.value.pageNum++;
      getList();
    }
  });
  // 返回上一页
  const goBack = () => {
    uni.navigateBack()
  }

  const handleDetail = (item) => {
    uni.navigateTo({
      url: `/pages/operate/detail?id=${item.id}`
    })
  }

</script>

<style lang="scss" scoped>
  .operate-page {
    min-height: 100vh;
    background: #fff;
    padding-bottom: 20rpx;

    // 顶部导航栏
    .header {
      height: 88rpx;
      background: #fff;
      display: flex;
      align-items: center;
      padding: 0 30rpx;
      position: relative;
      border-bottom: 1rpx solid #f5f5f5;

      .back-icon {
        font-size: 40rpx;
        color: #333;
      }

      .title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        font-size: 32rpx;
        font-weight: 500;
        color: #333;
      }
    }

    // 操作说明列表
    .operate-list {
      padding: 20rpx;

      .operate-item {
        display: flex;
        margin-bottom: 30rpx;
        padding: 0 10rpx;

        .item-image {
          width: 240rpx;
          height: 160rpx;
          border-radius: 12rpx;
          margin-right: 20rpx;
        }

        .item-content {
          flex: 1;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          padding: 10rpx 0;

          .item-text {
            font-size: 28rpx;
            color: #333;
            line-height: 1.4;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
          }

          .item-time {
            font-size: 24rpx;
            color: #999;
            margin-top: auto;
          }
        }
      }
    }
  }
</style>